import pandas as pd
import tushare as ts
import datetime
from datetime import date, timedelta
from ted_funs import *

pro = ts.pro_api('b2466a123789dae8056ddd5f58efabf0f93e6648e4f886ad110b4fc2')


print("...starting...")

days = days(20)

# 每日股票入库
for day in days:
	print(day)
	df = pro.daily(trade_date=day)
	df_new = df[['ts_code','trade_date', 'close']].copy()
	df_new['id'] = df['ts_code'] + '-' + df['trade_date']
	# print(df_new)
	try:
		mysql_write(df_new, 'daily')
	except Exception as e:
		pass

# 涨停股票入库
for day in days:
	print(day)
	df = pro.limit_list_d(trade_date=day, limit_type='U', fields='ts_code,trade_date,name,close,pct_chg')
	df_new = df.copy()
	df_new['id'] = df['ts_code'] + '-' + df['trade_date']
	# print(df_new)
	try:
		mysql_write(df_new, 'limit_list')
	except Exception as e:
		pass

print("...finished...")